// ignore_for_file: unused_local_variable

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:time_manager/utils/DataBaseRecord.dart';
import 'package:time_manager/utils/RecordModel.dart';

class PastController extends GetxController {
  var isLoading = false.obs;
  var list = <RecoreModel>[].obs;

  @override
  void onInit() async {
    // DataBaseRecord().deleteDb();
    await fetchRecordItem();
    super.onInit();
  }

  Future<void> onRefresh() async {
    await fetchRecordItem();
  }

  deleteItem(RecoreModel item) {
    Get.defaultDialog(
        title: '提示',
        content: const Text('您确定要删除吗？'),
        onCancel: () => Get.back(),
        onConfirm: () {
          DataBaseRecord().deleteRecord(item.id!);
          list.remove(item);

          Get.back();
          Get.snackbar('提示', '删除成功');
        });
  }

  // 获取当天日程
  fetchRecordItem() async {
    final result =
        await DataBaseRecord().selectRecord(orerBy: 'createTime desc');
    list.clear();
    list.assignAll(result);
  }
}
